package cs536.ast;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import cs536.ast.AbstractSyntaxTree.ExpressionStmt;
import cs536.ast.AbstractSyntaxTree.ReadStmt;
import cs536.ast.AbstractSyntaxTree.ReturnStmt;
import cs536.ast.AbstractSyntaxTree.VarDeclStmt;
import cs536.ast.AbstractSyntaxTree.WriteStmt;

import static cs536.ast.AbstractSyntaxTree.*;

public class TypesUnparser extends Unparser
{
	public String visitAst(AbstractSyntaxTree ast,
			List<String> declarationResults)
	{
		return "" + join(declarationResults, "");
	}

//	public String visitVarDeclStmt(VarDeclStmt localVar,
//			String typeResult, 
//			String initResult)
//	{
//		String name = localVar.getName();
//
//		if (initResult != null) {
//			return typeResult + " " + name + " = " + initResult + "; " + "/* " + 
//					localVar.getLocalSymbol().getType().getKind() + " */\n";
//		}
//		else {
//			return typeResult + " " + name + ";\n";
//		}
//	}


	public String visitReturnStmt(ReturnStmt retStmt, String valResult)
	{
		// 'valResult' is null if there is no return expression
		if (valResult != null) {
			return "return " + valResult + "; " + "/* " + 
					retStmt.getExpression().getType().getKind() + " */\n";
		}
		else {
			return "return;\n";
		}
	}

	public String visitExpressionStmt(ExpressionStmt exprStmt,
			String expResult)
	{
		return expResult + "; " + "/* " + exprStmt.getExpression().getType().getKind() + " */\n";
	}

//	public String visitWriteStmt(WriteStmt writeStmt, String valResult)
//	{
//		return "write " + valResult + "; " + "/* " 
//				+ writeStmt.getExpression().getType().getKind() + " */\n";
//	}


//	public String visitReadStmt(ReadStmt readStmt)
//	{
//		return "read " + readStmt.getDestinationName() + "; " + "/* " 
//				+ readStmt.getDestinationSymbol().getType().getKind() + " */\n";
//	}

}